<template>
	<view>
		<ad-rewarded-video></ad-rewarded-video>
		<uni-card>
			<template v-slot:cover>
				<image :src="resource.imgFile" :mode="scaleToFill" style="height: 380upx; width: 100%;"></image>
			</template>
			<uni-title type="h1" :title="resource.name" align="center" style="color: #398ADE;"></uni-title>

			<view style="display:flex; flex-direction:row; justify-content:center;">
				<uni-tag :text="resource.type" type="warning" style="margin-right: 20rpx;" />
				<uni-tag text="普通资源" type="error" />
			</view>

			<view style="margin-top: 10rpx;">
				<uni-row style="margin-top: 10rpx;">
					<uni-col :span="3">
						<text style="font-size: 30rpx; font-weight: 300; color: #303133;">简介:</text>
					</uni-col>
					<uni-col :span="21">
						<text style="font-size: 25rpx; font-weight: 200; color: #555555;">{{resource.introduce}}</text>
					</uni-col>
				</uni-row>
			</view>

			<view style="margin-top: 35rpx;">
				<uni-row style="margin-top: 10rpx;">
					<uni-col :span="3">
						<text style="font-size: 30rpx; font-weight: 300; color: #303133;">时间:</text>
					</uni-col>
					<uni-col :span="21">
						<text style="font-size: 25rpx; font-weight: 200; color: #555555;">{{resource.updateTime}}</text>
					</uni-col>
				</uni-row>
			</view>

			

		</uni-card>
		<button v-show="!showURL" type="primary" size="mini" style="display:flex; flex-direction:row; justify-content:center; width: 80%; margin-bottom: 50rpx;"  @click="getURL()"><uni-icons type="compose" color="#fff" size="15"></uni-icons>获取下载链接和提取码</button>
		
		<uni-card v-show="showURL">
			<view style="display:flex; flex-direction:row; justify-content:center; margin: 20rpx;">
				<text style=" font-weight: bold;">提取码:</text>
				<view v-if="resource.downloadPassword===''">
					<text style="font-size: 35rpx; font-weight: 200; color:#398ADE;">无提取码</text>
				</view>
				<view v-else>
					<text style="font-size: 35rpx; font-weight: 200; color:#398ADE;">{{resource.downloadPassword}}</text>
				</view>
				
			</view>
			<view style="display:flex; flex-direction:row; justify-content:center; margin-top: 20rpx;">
				<button type="primary" size="mini" style="width: 100%;" @click="copyPassword()"><uni-icons type="compose" color="#fff" size="15"></uni-icons>复制提取码</button>
			</view>
			
			<view style="display:flex; flex-direction:row; justify-content:center; margin-top: 10rpx;">
				<button type="primary" size="mini" style="width: 100%;" @click="copy()"><uni-icons type="download" size="15" color="#fff"></uni-icons>复制下载链接</button>
			</view>
			
		
		</uni-card>
		<ad unit-id="adunit-39b53761b10c9de2" ad-type="video" ad-theme="white"></ad>
	</view>
</template>

<script>
	import Utils from '../../Utils.js'
	export default {
		data() {
			return {
				showURL:false,
				resource: {}
			}
		},
		methods: {
			onLoad: function(e) {
				this.getResource(JSON.parse(e.id))
				uni.setNavigationBarTitle({
					title: this.resource.name
				})
				Utils.rewarded.load('adunit-a4cf3c070900384d', ()=>{
					this.showURL = true
				});
				
				
			},
			
			
			
			getURL(){
				uni.showModal({
				    title: '提示',
				    content: '需要观看广告才能获取哦',
				    success: function (res) {
				        if (res.confirm) {
							Utils.rewarded.show();
				            console.log('用户点击确定');
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
				
				
			},
			
			
			copy() {
				uni.setClipboardData({
					data: this.resource.downloadUrl,
				})
			},
			copyPassword() {
				uni.setClipboardData({
					data: this.resource.downloadPassword,
				})
			},
			
			getResource(id){
				uni.request({
					url: this.$api + '/resource/getById/' + id,
					header: {
						'content-type': 'application/x-www-form-urlencoded' //自定义请求头信息
					},
					method: 'GET',
					//请求成功后返回
					success: (res) => {
						// 请求成功之后将数据给Info
						if (res.data.code === '200') {
							this.resource = res.data.data;
							//时间截取
							this.resource.updateTime = this.resource.updateTime.slice(0, this.resource.updateTime
								.indexOf(" "));
							this.resource.imgFile = this.$api + '/img/' + this.resource.imgFile;
							
						}
				
					},
				
					fail: (res) => {
						console.log(res)
						uni.showToast({
							title: "请求错误:" + res.errMsg,
							icon: 'none',
							duration: 850
						});
					}
				
				});
			},
			
			
			
			
			
			
			
			
			//分享朋友
			onShareAppMessage(res) {
				return {
					title: this.resource.name,
					path: '/pages/resourcepage/resourcepage?id='+JSON.stringify(this.resource.id),
					imageUrl: this.resource.imgFile,
				}
			},
			//分享到朋友圈
			onShareTimeline(res) {
				return {
					title: "Howe科技-"+this.resource.name,
					path: '/pages/resourcepage/resourcepage?id='+JSON.stringify(this.resource.id),
					imageUrl: this.resource.imgFile,
				}
			},

		}
	}
</script>

<style>

</style>
